home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / bin / sysfs-update-devnames < prev    next >
Text File  |  2009-10-28  |  1KB  |  29 lines

  1. #! /bin/sh -e
  2. # Make sure that /etc/network/devnames is up to date, using sysfs. In
  3. # hotplug land, we may not get a chance to update it otherwise.
  4.  
  5. if [ ! -d /sys/class/net ] || ! type lspci >/dev/null 2>&1; then
  6.     exit
  7. fi
  8.  
  9. for dev in $(grep : /proc/net/dev | sort | cut -d: -f1); do
  10.     if grep "^$dev:" /etc/network/devnames >/dev/null 2>&1; then
  11.         continue
  12.     fi
  13.     if [ -f "/sys/class/net/$dev/device/vendor" ] && \
  14.        [ -f "/sys/class/net/$dev/device/device" ]; then
  15.         vendor="$(sed 's/^0x//' "/sys/class/net/$dev/device/vendor")"
  16.         device="$(sed 's/^0x//' "/sys/class/net/$dev/device/device")"
  17.         # 'tail -n 1' because for some reason lspci outputs two
  18.         # Device: lines.
  19.         vendorname="$(lspci -d "$vendor:$device" -m -v | grep ^Vendor: | tail -n 1 | sed 's/^Vendor:[[:space:]]*//; s/,/\\,/g')"
  20.         devicename="$(lspci -d "$vendor:$device" -m -v | grep ^Device: | tail -n 1 | sed 's/^Device:[[:space:]]*//; s/,/\\,/g')"
  21.         if [ "$vendorname" ] || [ "$devicename" ]; then
  22.             echo "$dev:$vendorname $devicename" >> /etc/network/devnames
  23.         fi
  24.     elif [ "$(readlink -f /sys/class/net/$dev/device/bus)" = /sys/bus/ieee1394 ] || \
  25.          [ "$(readlink -f /sys/class/net/$dev/device/bus)" = /sys/bus/firewire ]; then
  26.         echo "$dev:FireWire (IEEE 1394) Ethernet device" >> /etc/network/devnames
  27.     fi
  28. done
  29.